<?php
namespace app\admin\controller;

use app\admin\widget\Name;
use app\common\cache\agent\IAgentAdminCache;
use app\common\cache\total\PoolBidCache;
use app\common\cache\common\IAreaCache;
use app\common\cache\user\IUserCache;
use app\common\controller\AdminBaseController;
use app\common\enum\HolderType;
use app\common\enum\HtmlEnumValue;
use app\common\enum\IsAccumulationFund;
use app\common\enum\IsCar;
use app\common\enum\IsCompany;
use app\common\enum\IsCreditCard;
use app\common\enum\IsDelete;
use app\common\enum\IsHistory;
use app\common\enum\IsHouse;
use app\common\enum\IsPolicy;
use app\common\enum\IsSocial;
use app\common\cache\loan\ILoanFavoriteCache;
use app\common\enum\LoanType;
use app\common\enum\PoolBidStatus;
use app\common\enum\TenderStatus;
use app\common\ext\IBid;
use app\common\ext\IConfig;
use app\common\ext\IDb;
use app\common\ext\UserPoolBid;
use app\common\ext\IUrl;
use app\common\enum\Sex;
use app\common\ext\ILog;
use app\common\enum\UserPoolBidType;

class Ceshi extends AdminBaseController{
    /**
     * 计算时间差
     * @param int $timestamp1 时间戳开始
     * @param int $timestamp2 时间戳结束
     * @return array
     */
    public static function time_diff($timestamp1, $timestamp2)
    {
        $timestamp1 = strtotime($timestamp1);
        $timestamp2 = strtotime($timestamp2);
        dump($timestamp1);
        dump($timestamp2);
        dump($timestamp2-$timestamp1);
        if ($timestamp2 <= $timestamp1)
        {
            return ['day'=>0,'hours'=>0, 'minutes'=>0, 'seconds'=>0];
        }
        $timediff = $timestamp2 - $timestamp1;
        // 天
        $day = intval($timediff/86400);
        // 时
        $remain = $timediff%86400;
        $hours = intval($remain/3600);
        // 分
        $remain = $timediff%3600;
        $mins = intval($remain/60);
        // 秒
        $secs = $remain%60;
        $time = ['day'=>$day,'hours'=>$hours, 'minutes'=>$mins, 'seconds'=>$secs];
        return $time;
    }
    /**
     * @功能：已上架信用卡列表
     * @开发者：cxl
     * @return string
     */
    public function ceshi(){
        $order_num = PoolBidCache::getPoolBidNumInfo();
        $order_amount = PoolBidCache::getPoolBidMoneyInfo();
        $PoolBidNum = IConfig::getValue("PoolBidNum");
        $PoolBidMoney = IConfig::getValue("PoolBidMoney");
        $order_num = $order_num['order_num']+intval($PoolBidNum);
        $order_amount = $order_amount['order_amount']+intval($PoolBidMoney);

        $where['pool_bid_status'] = PoolBidStatus::BidStop;
        $order_list = IDb::getInstance('user_pool_bid as upb')
            ->setDbFiled('upb.user_pool_bid_id,upb.open_time,upb.bid_no,upb.money,upb.period,upb.user_id,upb.agent_admin_id')
            ->setDbWhere($where)
            ->setDbOrder("user_pool_bid_id desc")
            ->setDbLimit(5)
            ->sel();
        $order_list=null;
        if (empty($order_list)){
            $order_list = array(
                0=>array(
                    'user_pool_bid_id' => 361,
                    'open_time' =>  '2019-04-13 22:39:49' ,
                    'bid_no' =>  188361,
                    'money' =>  7664,
                    'period' =>  3,
                    'user_id' =>  741,
                    'agent_admin_id' =>  164,
                    'agent_admin_real' =>  '王经理',
                    'agent_admin_phone' =>  '188****7245',
                    'user_real' =>  'M女士',
                    'user_phone' =>  '182****7593',
                    'time' => '1天前',
                )
            );
        }
        foreach ($order_list as $key=>&$order){

            if(empty($order['agent_admin_id']) || empty($order['user_id'])){
                continue;
            }
            $admin_info = IAgentAdminCache::getInfo($order['agent_admin_id'],['real','business_phone']);
            $order['agent_admin_real'] = mb_substr($admin_info['real'],0,1).'经理';
            $order['agent_admin_phone'] = get_string_rsa($admin_info['business_phone'],3,4);

            $user_info = IUserCache::getInfo($order['user_id'],['real','sex','loan_phone']);
            $order['user_real'] = get_real_cover($user_info['real'],$user_info['sex']);
            $order['user_phone'] = get_string_rsa($user_info['loan_phone'],3,4);

            $time = time_diff($order['open_time'],get_date_time());
            if ($time['day']>=1){
                $order['time'] = '1天前';
            }else if($time['hours']>=1){
                $order['time'] = $time['hours'].'小时前';
            }else if ($time['minutes']>=1){
                $order['time'] = $time['minutes'].'分钟前';
            }else{
                $order['time'] = '1分钟前';
            }
        }
        dump($order_list);
    }
}